

package com.kimo.shop.delivery.api.listener;

import com.kimo.shop.bean.event.CalculateTransfeeEvent;
import com.kimo.shop.delivery.comment.service.TransportManagerService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 计算运费的监听事件
 *
 * @author kimo-taozhouchuan
 */
@Component("calculateTransFeeListener")
@AllArgsConstructor
public class CalculateTransFeeListener {

    private final TransportManagerService transportManagerService;

    /**
     * 计算运费的监听事件
     */
    @EventListener(CalculateTransfeeEvent.class)
    public void calculateTransFeeEvent(CalculateTransfeeEvent event) {
        double transfee = transportManagerService.calculateTransfee(event.getProductItem(), event.getUserAddr());
        event.setTransfee(transfee);
    }

}
